package cn.shengongying.model;

import com.github.wxpay.sdk.IWXPayDomain;
import com.github.wxpay.sdk.WXPayConfig;
import com.github.wxpay.sdk.WXPayConstants;
import com.github.wxpay.sdk.WXPayUtil;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * author: RXK
 * date: 2022/1/10 星期一
 * desc:
 */
public class ConfingWxPay extends WXPayConfig {

    public static final String key = "jiangrenkeji20200730jiangrenkeji";

    public static Map<String, String> prepayResult(Map<String, String> prepay) throws Exception {
        Map<String, String> result = new HashMap<>(8);
        result.put("appId", "wxeeb8390f971f8f20");
        result.put("timeStamp", String.valueOf(System.currentTimeMillis()));
        result.put("nonceStr", WXPayUtil.generateNonceStr());
        result.put("package", "prepay_id=" + prepay.get("prepay_id"));
        result.put("signType", "HMAC-SHA256");
        String signature = WXPayUtil.generateSignature(result, "jiangrenkeji20200730jiangrenkeji", WXPayConstants.SignType.HMACSHA256);
        result.put("paySign", signature);
        return result;
    }

    @Override
    protected String getAppID() {
        return "wxeeb8390f971f8f20";
    }

    @Override
    protected String getMchID() {
        return "1602176460";
    }

    @Override
    protected String getKey() {
        return key;
    }

    @Override
    protected InputStream getCertStream() {
        return this.getClass()
                .getClassLoader()
                .getResourceAsStream("appiclient_cert.p12");
    }

    @Override
    protected IWXPayDomain getWXPayDomain() {
        return new IWXPayDomain() {
            @Override
            public void report(String s, long l, Exception e) {

            }

            @Override
            public DomainInfo getDomain(WXPayConfig wxPayConfig) {
                return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API,true);
            }
        };
    }



}
